<?php

require_once('model/UserDataParser.php');

class Controller
{
    public function __construct()
    {
        $result = $this->executeRequest();
        $this->parseResponse($result);
    }
    
    public function __destruct()
    {
        
    }
    
    private function executeRequest()
    {
        //If we arrive here using a strange method, escape
        if(!isset($_REQUEST['function']))
            return "There's an error while parsing the values";
        $params;
        //We create a local version of the recieved params
        foreach($_REQUEST as $key=>$value)
        {
            $params[$key] = $value;
        }
        //Looking for the matching function. If undefined, return an error
        switch($params['function'])
        {
            /* Case example
             * case "select":
             * $var = new SelectController($params);
             * return $var; break; //break isn't necessary at all, but let's be polite.
             */
            case "users":
                $var = new UserDataParser($params);
                return $var->getResponse(); break;
            default:
                return "There's an error while parsing the values"; break;
        }
    }
    private function parseResponse($result)
    {
         echo $result->getBody();
    }
}

$_REQUEST['function'] = "users";
$tmp = new Controller();
?>
